#include<bits/stdc++.h>
#include<stack>
using namespace std;
int main(){
	stack<int> s1,s2;
	int n1,n2,data;
	cin>>n1>>n2;
	char ch;
	while((ch=getchar())!='T'){
		if(s1.size()==n2&&s2.empty()){
			while(s2.size()!=n2){
				data=s1.top();
				s1.pop();
				s2.push(data);
			}
		}
		switch(ch){
			case 'A':
				cin>>data;
				if(s1.size()==n2&&!s2.empty()){
					cout<<"ERROR:Full"<<endl;
				}
				else {
					s1.push(data);					
				}
				break;
			case 'D':
				if(s2.empty()) cout<<"ERROR:Empty"<<endl;
				else {
					data=s2.top();
					s2.pop();
					cout<<data<<endl;
				}
			default:
				break;
		}
	}
	return 0;
} 
